<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form" :inline="true" label-width="130px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="补贴单号">
              <el-input v-model="form.applySn" placeholder="请输入补贴单号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="姓名">
              <el-input v-model="form.realname" placeholder="请输入姓名"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="手机号">
              <el-input v-model="form.username" placeholder="请输入手机号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="保险分类">
              <el-select v-model="form.insureType" placeholder="请选择">
                <el-option
                  v-for="item in insureOptions"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="审核状态">
              <el-select v-model="form.applyStatus" placeholder="请选择">
                <el-option
                  v-for="item in applyOptions"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="创建时间">
              <el-date-picker
                type="daterange"
                value-format="yyyy-MM-dd"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                v-model="times"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-button @click="searchFn" style="margin-left:60px" type="primary">查询</el-button>
            <!-- 导出按钮权限 -->
            <!-- v-if="permissionJson.indexOf('AdminPlatformFeeProvider.export') !=-1" -->
            <el-button class="el-icon-download" plain @click="excelEvent" type="primary">导出</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- table -->
    <div class="table" v-loading="tableLoading">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column type="index" label="序号" fixed="left" :index="table_index" width="50"></el-table-column>
        <el-table-column prop="applySn" label="补贴单号"></el-table-column>
        <el-table-column prop="realname" label="姓名"></el-table-column>
        <el-table-column prop="username" label="电话">
          <template slot-scope="scope">
            <div>{{scope.row.username | phonereg }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="identity" label="身份证"></el-table-column>
        <el-table-column prop="hospitalName" label="医院"></el-table-column>
        <el-table-column prop="projectName" label="项目"></el-table-column>
        <el-table-column prop="applyStatus" label="审核状态">
          <template slot-scope="scope">{{ scope.row.applyStatus}}</template>
        </el-table-column>
        <el-table-column prop="insureType" label="保险分类">
          <template slot-scope="scope">{{ scope.row.insureType}}</template>
        </el-table-column>
        <el-table-column prop="insurePrice" label="保险金额"></el-table-column>
        <el-table-column prop="insureDeduct" label="已扣除金额"></el-table-column>
        <el-table-column prop="createTime" label="创建时间"></el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <div class="pagesCon">
      <div>
        <el-pagination
          :current-page="form.pageNum"
          :page-sizes="page_sizes"
          :page-size="form.limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="page_totals"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>
<script>
import { handlingfeeGetNew, handlingExport } from "@/api/financialOther";
import { exportfile } from "@/api/exporfile";
export default {
  name: "handlingfee",
  data() {
    return {
      permissionJson: JSON.parse(localStorage.getItem("permissionJson")),
      tableLoading: true,
      tableData: [],
      total: 0,
      times: [],
      form: {
        applySn: null,
        realname: null,
        username: null,
        insureType: null,
        applyStatus: null,
        createdAtStart: null,
        createdAtEnd: null,
        pageNum: 1,
        pageSize: 10
      },
      page_sizes: [10, 30, 50, 100],
      page_totals: 60,
      insureOptions: [
        { id: 0, name: "全部" },
        { id: 1, name: "微整型" },
        { id: 2, name: "皮肤美容" },
        { id: 3, name: "私密整型" },
        { id: 4, name: "眼部整型" },
        { id: 5, name: "鼻部整型" },
        { id: 6, name: "自体脂肪" },
        { id: 7, name: "美体塑形" },
        { id: 8, name: "面部轮廓" },
        { id: 9, name: "乳房整型" }
      ],
      applyOptions: [
        { id: null, name: "全部" },
        { id: 0, name: "未审核" },
        { id: 1, name: "通过" },
        { id: 2, name: "不通过" },
        { id: 3, name: "初审" },
        { id: 4, name: "协议未签名" }
      ]
    };
  },
  filters: {
    // 审核状态
    applyStatusFilter(e) {
      switch (e) {
        case 0:
          return "未审核";
        case 1:
          return "通过";
        case 2:
          return "不通过";
        case 3:
          return "初审";
        case 4:
          return "协议未签名";
        default:
          return "暂无";
      }
    },
    // 保险分类
    insureTypeFilter(e) {
      switch (e) {
        case 1:
          return "微整型";
        case 2:
          return "皮肤美容";
        case 3:
          return "私密整型";
        case 4:
          return "眼部整型";
        case 5:
          return "鼻部整型";
        case 6:
          return "自体脂肪";
        case 7:
          return "美体塑形";
        case 8:
          return "面部轮廓";
        case 9:
          return "乳房整型";
        default:
          return "暂无";
      }
    }
  },
  mounted() {
    this.getList(this.form);
  },
  methods: {
    //获取列表
    getList(e) {
      const datas = e;
      handlingfeeGetNew(datas)
        .then(res => {
          console.log(res);
          if (!res.data.code) {
            this.tableData = res.data.data.list;
            this.page_totals = res.data.data.count;
          } else {
            this.$message.error(res.data.msg);
          }
          this.tableLoading = false;
        })
        .catch(error => {
          this.$message.error(error);
          this.tableLoading = false;
        });
    },
    table_index(index) {
      return (this.form.pageNum - 1) * this.form.pageSize + index + 1;
    },
    // 查询
    searchFn() {
      this.form.pageNum = 1;
      if (this.times != null) {
        if (this.times.length) {
          this.form.createdAtStart = this.times[0];
          this.form.createdAtEnd = this.times[1];
        }
      } else {
        this.form.createdAtStart = null;
        this.form.createdAtEnd = "";
      }
      // console.log(this.form)
      this.getList(this.form);
    },
    //导出
    excelEvent() {
      let datas = { ...this.form };
      delete datas.pageNum;
      delete datas.pageSize;
      handlingExport(datas).then(res => {
        exportfile(res);
      });
    },
    // 改变页面条数
    handleSizeChange(val) {
      this.form.pageSize = val;
      this.getList(this.form);
    },
    // 选择页数
    handleCurrentChange(val) {
      this.form.pageNum = val;
      this.getList(this.form);
    }
  }
};
</script>
<style scoped>
/* 分页 */
.pagesCon {
  height: 40px;
  margin-top: 20px;
}
.pagesCon > div {
  float: right;
}
/* 表单样式修改 */
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
</style>
